package com.augurit.wf.bi.convert;

import java.util.ArrayList;
import java.util.List;

import com.augurit.wf.bi.web.form.WfActElemPrivDefForm;
import com.augurit.wf.bi.web.form.WfPageElementForm;
import com.augurit.wf.common.entity.WfPageElement;

public class WfPageElementConvertor {
	public static WfPageElementForm convertVoToForm(WfPageElement entity) {
		if(entity != null) {
			WfPageElementForm form = new WfPageElementForm();
			form.setId(entity.getId());
			form.setElementCode(entity.getElementCode());
			form.setElementName(entity.getElementName());
			form.setParentId(entity.getParentId());
			form.setElementType(entity.getElementType());
			form.setElementGroup(entity.getElementGroup());
			form.setIsActive(entity.getIsActive());
			form.setMemo(entity.getMemo());
			form.setIsPublic(entity.getIsPublic());
			form.setElementTip(entity.getElementTip());
			form.setSmallImgPath(entity.getSmallImgPath());
			form.setMiddleImgPath(entity.getMiddleImgPath());
			form.setBigImgPath(entity.getBigImgPath());
			form.setElementInvoke(entity.getElementInvoke());
			form.setElementSortNo(entity.getElementSortNo());
			form.setGroupSortNo(entity.getGroupSortNo());
			form.setElementInvokeMode(entity.getElementInvokeMode());
			return form;
		}else
			return null;
	}
	
	public static void convertFormToVo(WfPageElementForm form, WfPageElement entity) {
		if(entity != null && form != null) {
			entity.setId(form.getId());
			if(form.getElementCode() != null && form.getElementCode().trim().length() > 0)
				entity.setElementCode(form.getElementCode().trim());
			if(form.getElementName() != null && form.getElementName().trim().length() > 0)
				entity.setElementName(form.getElementName().trim());
			if(form.getParentId() != null)
				entity.setParentId(form.getParentId());
			if(form.getElementType() != null && form.getElementType().trim().length() > 0)
				entity.setElementType(form.getElementType().trim());
			if(form.getElementGroup() != null && form.getElementGroup().trim().length() > 0)
				entity.setElementGroup(form.getElementGroup().trim());
			if(form.getIsActive() != null && form.getIsActive().trim().length() > 0)
				entity.setIsActive(form.getIsActive().trim());
			if(form.getMemo() != null && form.getMemo().trim().length() > 0)
				entity.setMemo(form.getMemo().trim());
			if(form.getIsPublic() != null && form.getIsPublic().trim().length() > 0)
				entity.setIsPublic(form.getIsPublic().trim());
			if(form.getElementTip() != null && form.getElementTip().trim().length() > 0)
				entity.setElementTip(form.getElementTip().trim());
			if(form.getSmallImgPath() != null && form.getSmallImgPath().trim().length() > 0)
				entity.setSmallImgPath(form.getSmallImgPath().trim());
			if(form.getMiddleImgPath() != null && form.getMiddleImgPath().trim().length() > 0)
				entity.setMiddleImgPath(form.getMiddleImgPath().trim());
			if(form.getBigImgPath() != null && form.getBigImgPath().trim().length() > 0)
				entity.setBigImgPath(form.getBigImgPath().trim());
			if(form.getElementInvoke() != null && form.getElementInvoke().trim().length() > 0)
				entity.setElementInvoke(form.getElementInvoke().trim());
			entity.setElementSortNo(form.getElementSortNo());
			entity.setGroupSortNo(form.getGroupSortNo());
			if(form.getElementInvokeMode() != null && form.getElementInvokeMode().trim().length() > 0)
				entity.setElementInvokeMode(form.getElementInvokeMode().trim());
		}
	}
	
	public static List<WfPageElementForm> convertVoListToFormList(List<WfPageElement> wfPageElementList) {
		if(wfPageElementList != null && wfPageElementList.size() > 0) {
			List<WfPageElementForm> wfPageElementFormList = new ArrayList();
			for(int i=0; i<wfPageElementList.size(); i++) {
				wfPageElementFormList.add(convertVoToForm(wfPageElementList.get(i)));
			}
			return wfPageElementFormList;
		}
		return null;
	}
	
	public static List<WfPageElement> convertFormListToVoList(List<WfPageElementForm> wfPageElementFormList) {
		if(wfPageElementFormList != null && wfPageElementFormList.size() > 0) {
			List<WfPageElement> wfPageElementList = new ArrayList();
			for(int i=0; i<wfPageElementFormList.size(); i++) {
				WfPageElement wfPageElement = new WfPageElement();
				convertFormToVo(wfPageElementFormList.get(i), wfPageElement);
				wfPageElementList.add(wfPageElement);
			}
			return wfPageElementList;
		}
		return null;
	}
	
	public static List<WfPageElementForm>  convertMulEntityListToFormList(List<Object []> objsList){
		List<WfPageElementForm> result = null;
		if(objsList != null && objsList.size() > 0){
			result = new ArrayList<WfPageElementForm>();
			for(Object [] objs:objsList){
				WfPageElement entity = (WfPageElement)objs[0];
				String templateName = (String)objs[1];
				WfPageElementForm form = convertVoToForm(entity);
				form.setTemplateName(templateName);
				result.add(form);
			}
		}
		return result;
	}
	
}